package fina2.dcs.fis;

import java.io.Serializable;
import java.math.BigDecimal;

import javax.ejb.EJB;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jboss.annotation.ejb.LocalBinding;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.log.Log;

import fina2.dcs.i18n.LanguageSession;
import fina2.dcs.system.SysString;
import fina2.dcs.system.SysStringLocal;
import fina2.dcs.system.SysStringPk;

@Stateful
@Name("manBodySession")
@Scope(ScopeType.SESSION)
@LocalBinding(jndiBinding = "ManagingBodySession/local")
@AutoCreate
public class ManagingBodySession implements ManagingBodyLocal,Serializable {

	@PersistenceContext
	private EntityManager em;

	@EJB
	private SysStringLocal sysStringLocal;
	
	@Logger
	private Log log;

	public ManagingBody findById(BigDecimal id) {
		ManagingBody mb = null;
		try {
			mb = em.find(ManagingBody.class, id);
			if (mb != null) {
				SysString ss = sysStringLocal.findByPk(new SysStringPk(mb.getPostStrId(), LanguageSession.langId));
				mb.setPost((ss != null) ? ss.getValue() : null);
			}
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);

		}
		return mb;
	}

	@Remove
	@Destroy
	public void remove() {

	}

}
